// pages/user-my-order-refund/user-my-order-refund.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderNum: "", //订单号
    orderId: "", //申请售后
    content: "", //内容
    currentTab: 1, //默认对号
    color: 1, //默认然色
    name: '质量问题', //退换货原因
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log('--a-', options)
    var orderNum = options.orderNum
    var orderId = options.orderId
    this.setData({
      orderNum: orderNum,
      orderId: orderId,
    })

  },

  // 保存信息
  save: function(e) {
    var that = this
    //内容
    this.setData({
      content: e.detail.value
    });
  },

  // 提交申请
  apply: function(e) {

    var that = this;
    let { orderId, content, name, color} = this.data;
    if(content==''){
      wx.showToast({
        title: '请填写问题描述',
        icon:'none',
        duration:1000
      });
    }
    else{
      app.request({
        url: 'shopp/goodsOrderApi/submitExchangeGoods', //仅为示例，并非真实的接口地址
        data: {
          id: orderId, //术前术后的
          describe: content, //问题描述
          problem: name, //退换原因
          type: color, //1退货  2换货
        },
        success(res) {
          wx.switchTab({
            url: '/pages/doctor-my/doctor-my',
          })
          wx.showToast({
            title: '申请成功，等待审核',
            icon: 'success',
            duration: 1000,
          })
        }
      })
    }

  },
  //默认然色
  cickTab: function(e) {
    var that = this;
    if (this.data.color == e.target.dataset.current) {

    } else {
      that.setData({
        color: e.target.dataset.current
      })
    }
  },
  //对号切换
  clickTab: function(e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {

    } else {
      that.setData({
        currentTab: e.target.dataset.current,
        name: e.target.dataset.name
      })
    }
  }
})